<?php
defined('_JEXEC') or die('Restricted access');
$app = JFactory::getApplication();
$input = $app->input;
$itemid = $input->get('Itemid');

$item  = $input->getArray();
$rpt = json_decode($item['report']);
$names = array();
foreach($rpt->sessions->data as $d) {
	$names[$d->key] = null;
}
foreach($rpt->sessionDuration->data as $d) {
	$names[$d->key] = null;
}
$vName = $input->get('view');
?>
<div class="res-title-rg">
    <span class="fl pos-icon text-c"><i class="audience"></i></span>
    <div class="title-info">
        <h2 class="fontsize20">Operators</h2>
        <p><a href="#">Home</a>&nbsp;/&nbsp;Audience&nbsp;/&nbsp;Operators</p>
    </div>
</div>
<div class="ws-content pdall15">
	<div id="chart" style="height:560px"></div>
</div>
<script type="text/javascript">
	var chart = createDoublePieChart({
		divId: 'chart',
		title: '<?php echo $rpt->sessions->name?>',
		pie1Name: 'Sessions',
		pie1Values: [
	        <?php foreach($rpt->sessions->data as $d):?>
	        {name: "<?php echo $d->key?>", value: <?php echo $d->value?>},
	        <?php endforeach;?>
	    ],
	    pie2Name: 'Average Session Duration',
	    pie2Values: [
	    	<?php foreach($rpt->sessionDuration->data as $d):?>
	        {name: "<?php echo $d->key?>", value: <?php echo $d->value?>},
	        <?php endforeach;?>
	    ]
	});
	chart.setOption({
		tooltip: {
	        trigger: 'item',
	        formatter: function(param, ticket, callback) {
	            if (param.seriesIndex == 1) {
	                return 'Average Session Duration<br>' + formatAsTime(param.value);
	            }
	            else {
	                return 'Sessions<br>' + param.name + ': ' + param.value;
	            }
	        }
	    },
	});
</script>
